from inspect import isclass
from adapt.interface.IRecipe import IRecipe
class Repository(object):
    def __init__(self):
        self.__recipes = []
    
    def add(self, module):
        """reads module and load all recipes--that is all classes that inherit from IRecipe and are not interfaces (do not start from I)"""
        
        # read all defined objects from the module
        # recipe container (rcontainer)
        for obj_id in dir(module):
            obj = getattr(module, obj_id)
            # detect recipes defined in the rcontainer: it must be
            if self.__is_recipe(obj):
                self.add_recipe(obj)

    def add_recipe(self, recipe):
        self.__recipes.append(recipe())

                
    def find(self, sth):
        pass
    
    def __is_recipe(self, obj):
        return isclass(obj) and issubclass(obj, IRecipe) and not obj.__name__.startswith("I") 
    